// const app = getApp()
// const util = require('../../../utils/util.js')
const lbbService = require('../../../pages/service/service.js');
const lbbTaskService = require('../service/task-service.js');
const lbbInneralTaskService = require('../service/task-inneral-service');


Page({

  /**
   * 页面的初始数据
   */

  data: {
    propArray: [],
    hosPhotoInfo:[],
    isRoutingStaticMenus: 1,
    stat:0,
    page:1,
    limit:5,
    workerPhone:'',
    proId:0,
    cityId:0,
    villageId:0,
    background: "#f2f2f2",
    isBackBtn: true, // 设置是否显示回到顶部按钮
    isEmpty: false, // 设置是否为空数据
    baseConfig: {
        shake: true, // 是否开启下拉震动
        height: 70, // 下拉高度
        text: {
          color: "#fff", // 文字颜色
          shadow: 5, // 是否开启shadow阴影,0为不开启,数值越大阴影范围越大
        },
        background: {
          color: "#000000",
          height: 120, // 设置背景大于下拉高度
          img: "https://test.wzs.pub/pic/bg.jpg",
        },
    },
    val: 0,
    defaultSetting: {
      shake: true, // 设置是否开启震动
      style: "black", // 设置圆点申诉还是浅色
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const vm = this
    vm.getTaskFeedbackStaticInfo()
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {      
      this.getTaskFeedbackStaticInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  navToDetailView(e) {
    console.log("toTaskView--->", e)
    let data = e.currentTarget.dataset;
    if (this.data.stat==0) {
        wx.navigateTo({
          url: '/pkgTask/pages/task-feedback-detail/index?taskId='+data.taskid+'&tipId='+data.tipid+'&state=add',
        })
    } else if (this.data.stat ==1) {
        wx.navigateTo({
          url: '/pkgTask/pages/task-feedback-detail/index?taskId='+data.taskid+'&tipId='+data.tipid+'&state=edit',
        })
    }
    
  },

  changeStat(event){
      let stat = event.detail
      console.log("---->", stat)
      this.setData({
          stat:stat
      })
    //   this.data.stat = stat
      console.log("----aa>", stat)
      this.data.page = 1
      console.log("----list>",this.feedbackTaskList)
      this.getTaskFeedbackStaticInfo() 
  },

  getTaskFeedbackStaticInfo() {
    let that = this
    const data  = {
        isFb: that.data.stat, 
        pageNo: that.data.page,
      }
    lbbInneralTaskService.getFeedbackRecordList(data, function (res){
      if(res.result == 0) {  
        console.log(res)
        console.log(data)
        // that.setData({
        //     feedbackTaskList:[{
        //         taskId:111,
        //         taskName:'任务一',
        //         addTime:'2022-08-16 12:00'
        //     },{
        //         taskId:112,
        //         taskName:'任务二',
        //         addTime:'2022-08-16 12:00'
        //     }]
        // })
        console.log(that.data.page)
        console.log(res.data.pages)
        if (that.data.page == res.data.pages) {
        
          that.data.isEmpty = true
          that.setData({
            feedbackTaskList:res.data.records
          })
        } else if (that.data.page < res.data.pages) {
            that.setData({
                feedbackTaskList:res.data.records
            })
        }
      }     
    }) 
  },

  onReachBottom() {
    // this.setData({
    //   page:this.data.page + 1
    // })
    // this.getTaskFeedbackStaticInfo()
  },

  scrolltoupper() {
    console.log(this.data.page)
    if (this.data.page >1) {
      this.setData({
        page:this.data.page - 1
      })
      this.getTaskFeedbackStaticInfo()
    } 
  },

  scrolltolower() {
    console.log(this.data.page)
    this.setData({
      page:this.data.page + 1
    })
    this.getTaskFeedbackStaticInfo()
  },
  loadmore() {
    console.log(this.data.page)
    this.setData({
      page:this.data.page + 1
    })
    this.getTaskFeedbackStaticInfo()
    // 上拉到底部，加载更多时执行，请实现分页+1，新数据加载的操作
  },
  refresh() {
    console.log(this.data.page)
    if (this.data.page >1) {
      this.setData({
        page:this.data.page - 1
      })
      this.getTaskFeedbackStaticInfo()
    } 
    
    // 下拉到顶部，下拉刷新时执行，请实现清除列表数据，还原分页为初始值的操作
  },
//   onPullDownRefresh() {
//     console.log(this.data.page)
//     if (this.data.page==1) {
//         this.getTaskFeedbackStaticInfo()
//     }else if (this.data.page >1) {
//       this.setData({
//         page:this.data.page - 1
//       })
//       this.getTaskFeedbackStaticInfo()
//     } 
//   },
})